// JavaScript Document

function criaMenu(menus)
{
	$('#submenu #content_submenu').html(''); 
	
	for(var i=0;i<menus.length;i++)
	{
		$('#submenu #content_submenu').append('<span class="separator">&nbsp;</span>');
		$('#submenu #content_submenu').append('<span class="menu_option">'+menus[i].label+'</span>');
		
		
		
		$('#submenu #content_submenu').append('<span class="separator">&nbsp;</span>');
		
	}
	
	$('#submenu .menu_option').each(function(index){
			
			$(this).click(function(){

				window.location = menus[index].location;
			})
			
		}); 
	
}

$(document).ready(function(){
	
	$('button').button();
	
	$('#bt_sair').bind('mouseover',function(){
		
		$('#bt_sair img').attr('src','/BancoRioDeAlimentos/jsp/images/botao_sair_rollover.png');
		$('#bt_sair span').css('color','white');
		
		
	});
	
	$('#bt_sair').bind('mouseout',function(){
		
		$('#bt_sair img').attr('src','/BancoRioDeAlimentos/jsp/images/botao_sair.png');
		$('#bt_sair span').css('color','#333333');
		
		
	});
        
        $('#bt_sair').click(function(){
            
            
            window.location = '/BancoRioDeAlimentos/logout.action';
        })
        
        var contexto = '/BancoRioDeAlimentos/show_';
      	
	//--------------- menu principal------------------- 
	
        
        
	$('.menu_option').click(function(){
		
		var menu = $(this).attr('id'); 
		var menus; 
		
		if(menu=='Instituicao')
		{
			
			var submenu1 = {}; 
			    submenu1.label = 'Nova Institui&ccedil;&atilde;o';				
			    submenu1.location = contexto+'cadastro_Instituicao'; 
                            
			var submenu2 = {}; 
		            submenu2.label = 'Buscar Institui&ccedil;&atilde;o'; 
			    submenu2.location = contexto+'busca_Instituicao'; 
                            
                            var submenu3 = {}; 
                            submenu3.label = 'Relat&oacute;rios';
                            submenu3.location = contexto+'relatorio_Instituicao';
			
                        menus = [submenu1,submenu2,submenu3]; 	
		}
		else
		   	if(menu=='Logistica')
		{
			
			var submenu1 = {}; 
			    submenu1.label = 'Nova/Buscar Log&iacute;stica';				
			    submenu1.location = contexto+'cadastro_Logistica'; 
                            
 
					menus = [submenu1]; 	
		}
		else
		   	if(menu=='Municipio')
		{
			
			var submenu1 = {}; 
			    submenu1.label = 'Novo Local';
				
			    submenu1.location = contexto+'cadastro_Municipio'; 
				var submenu2 = {}; 
		            submenu2.label = 'Buscar Local'; 
					submenu2.location = contexto+'busca_Municipio';  
					menus = [submenu1,submenu2]; 	
		}
		else
	       	if(menu=='Usuario')
		{
			
			var submenu1 = {}; 
			    submenu1.label = 'Novo Usu&aacute;rio';
				
			   submenu1.location = contexto+'cadastro_Usuario'; ; 
				var submenu2 = {}; 
		            submenu2.label = 'Buscar Usu&aacute;rio'; 
					submenu2.location = contexto+'busca_Usuario';  
					menus = [submenu1,submenu2]; 	
		}
                
              /*  else
	       	if(menu=='BancoDeAlimentos')
		{
			
			var submenu1 = {}; 
			    submenu1.label = 'Novo Banco de Alimentos';
				
			    submenu1.location = contexto+'cadastro_BancoDeAlimentos'; 
				var submenu2 = {}; 
		            submenu2.label = 'Buscar Banco de Alimentos'; 
					submenu2.location = contexto+'busca_BancoDeAlimentos';  
					menus = [submenu1,submenu2]; 	
		}*/
                
                else
                    if(menu=='Voluntarios')
                        {
                            
                            var submenu1 = {}; 
			    submenu1.label = 'Novo Volunt&aacute;rio';
				
			    submenu1.location = contexto+'cadastro_Voluntario'; 
				var submenu2 = {}; 
		            submenu2.label = 'Buscar Volunt&aacute;rio'; 
					submenu2.location = contexto+'busca_Voluntario';  
					menus = [submenu1,submenu2]; 	
                            
                        }
		
		
		criaMenu(menus); 
		
	}); 
        
        
        //---------------selecionando menu corrente--------------
     
        var url = window.location.pathname; 
        
        var currentPage = url.split('_'); 
        
        currentPage = currentPage[2].split('.')
        
        $('#'+currentPage[0]).click(); 
        
	
});

